<template>
	<view class="page">
		<view class="page-header-container">
			<view class="search-warpper">
				<u-search placeholder="患者姓名" v-model="keyword" @search='getTableData(1)'
					@custom='getTableData(1)'></u-search>
			</view>
			<view class="tabs-warpper">
				<u-tabs :list="tabsList" :scrollable="false" keyName='name' @change='tabsChange'></u-tabs>
			</view>
		</view>
		<!-- <view v-show="totalElements===0" style="color: #909090;display: flex; justify-content: center;">
			暂无数据
		</view> -->
		<view class="referral-list-container" v-for="(item,index) in tableData">

			<view class="referral-item">
				<view class="item-header">
					<view class="patient-info">
						<text class="patient-name">{{item.memberName}}</text>
						<text class="patient-gender">{{item.gender===1?'男':item.gender===2?'女':''}}</text>
						<!-- <text class="patient-age">30岁</text> -->
						<text class="patient-phone-no">{{item.age}}</text>
					</view>
					<view class="status">{{getTranStatus(item.tranStatus)}}</view>
				</view>
				<view class="item-footer">
					<text class="apply-for-time">申请时间: {{item.updateTime}}</text>
					<view class="detail-link" @click="toDetail(item.id)">
						<text class="text">查看详情</text>
						<u-icon color="#3c9cff" name="arrow-right-double" size="18px"></u-icon>
					</view>
				</view>
			</view>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>

</template>

<script>
	import {
		requestlist
	} from '@/common/api/referral/list/list.js'
	export default {
		data() {
			return {
				totalElements: 0,
				keyword: '',
				tableData: [],
				tabsList: [{
						name: '全部',
						id: ''
					},

					{
						name: '门诊',
						id: '0'
					},
					{
						name: '住院',
						id: '1'
					},
					{
						name: '未到诊',
						id: 5
					},
				],
				tranStatusList: [{
						name: '暂存',
						value: 1
					},
					{
						name: '撤销',
						value: 2
					},
					{
						name: '待审核',
						value: 3
					},
					{
						name: '驳回',
						value: 4
					},
					{
						name: '未到诊',
						value: 5
					},
					{
						name: '待到诊',
						value: 6
					},
					{
						name: '已到诊',
						value: 8
					},
					{
						name: '已完成',
						value: 9
					},
					{
						name: '需随访',
						value: 10
					},
					{
						name: '随访中',
						value: 11
					},
				],
				pageInfo: {
					total: 0,
					offset: 0,
					limit: 10,
				},
				EQ_receiveType: '',
				EQ_tranStatus: '',
				tabsName: '',
			}
		},
		onShow() {
			this.pageInfo.offset=0
			this.getTableData(1)
		},			
		// 触底的事件
		onReachBottom() {
			if (this.pageInfo.offset / 10 + 1 >= this.pageInfo.total) {
				return this.$refs.uToast.show({
					type: "default",
					message: "已加载全部数据",
				})
			}


			// 让页码值自增+1
			this.pageInfo.offset += 10
			this.getTableData(2)
		},
		methods: {
			// 去往详情页
			toDetail(id) {
				uni.navigateTo({
					url: '/pages/referral/detail/detail?id=' + id
				});
			},
			// 获取列表数据
			getTableData(val) {

				let data = {
					sort: "id",
					order: "desc",
					offset: this.pageInfo.offset,
					limit: 10,
					transferFilterMap: {
						EQ_applyDoctorId: uni.getStorageSync('doctorId'),
						EQ_tranType: "0",
						GTE_createTime: "",
						LIKE_applyCode: "",
						LIKE_applyDoctorName: "",
						LIKE_memberName: this.keyword ? '%' + this.keyword + '%' : '',
						LIKE_tranHospitalName: "",
						LTE_createTime: "",
					},
				}
				if (this.tabsName === '未到诊') {
					data.transferFilterMap.EQ_tranStatus = 5
				}
				if (this.tabsName === '全部') {
					data.transferFilterMap.EQ_receiveType = ''
					data.transferFilterMap.EQ_tranStatus = ''
				}
				if (this.tabsName === '门诊') {
					data.transferFilterMap.GTE_tranStatus = 8
					data.transferFilterMap.LTE_tranStatus = 9

				}
				if (this.tabsName === '住院') {
					data.transferFilterMap.GTE_tranStatus = 8
					data.transferFilterMap.LTE_tranStatus = 9
					data.transferFilterMap.EQ_receiveType = 1

				}
				requestlist(data).then(response => {
					if (response.code == 1) {

						if (val == 1) {
							this.tableData = response.object.content
						} else {
							this.tableData.push(...response.object.content)
						}
						this.pageInfo.total = response.object.totalPages;
						this.totalElements = response.object.totalElements
					}
				});
			},
			getTranStatus(val) {
				const status = this.tranStatusList.find(item => item.value === val);
				return status.name
			},
			// 切换标签事件
			tabsChange(e) {
				this.tabsName = e.name
				this.pageInfo.offset = 0
				this.pageInfo.limit = 10
				this.getTableData(1)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.page-header-container {
		background: #fff;

		.search-warpper {
			padding: 0 32rpx
		}
	}

	.referral-list-container {
		.referral-item {
			margin: 15px auto 0;
			padding: 10px;
			width: 686rpx;
			border-radius: 10px;
			background-color: #fff;
			box-sizing: border-box;

			.item-header {
				margin-bottom: 10px;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.patient-info {
					font-size: 0;

					.patient-name {
						color: $text-main-color;
						font-size: $ft-size-md;
						font-weight: bold;
					}

					.patient-gender {
						margin-left: 5px;
						color: $text-content-color;
						font-size: $ft-size-base;
					}

					.patient-age {
						margin-left: 5px;
						color: $text-content-color;
						font-size: $ft-size-base;
					}

					.patient-phone-no {
						margin-left: 5px;
						color: $text-content-color;
						font-size: $ft-size-base;
					}
				}

				.status {
					color: $text-desc-color;
					font-size: $ft-size-base;
				}
			}

			.item-footer {
				margin-top: 10px;
				display: flex;
				justify-content: space-between;

				.apply-for-time {
					color: $text-content-color;
					font-size: $ft-size-sm;
				}

				.detail-link {
					display: flex;
					justify-content: space-between;
					align-items: center;

					.text {
						color: $primary;
						font-size: $ft-size-base;
					}
				}
			}
		}
	}
</style>